package com.example.music.controller;

import com.example.music.domain.User;
import com.example.music.service.IUserService;
import com.example.music.util.AjaxResult;
import com.example.music.util.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Anonymous
@Api(tags = "用户管理(224 魏川子)")
@RestController
@RequestMapping("/api/users")
public class UserController  {

    @Autowired
    private IUserService userService;


    @ApiOperation(value = "获取所有用户的信息(224 魏川子)",notes = "获取所有用户的信息")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(userService.getUsers());
    }

    @ApiOperation(value = "根据id查找用户信息(224 魏川子)",notes = "根据id查找客户信息")
    @GetMapping("/{id}")
    public AjaxResult getUserById(@PathVariable("id")Long id){
        return AjaxResult.success(userService.selectUserById(id));
    }

    @ApiOperation(value = "新增用户 (224 魏川子)",notes = "新增一个用户")
    @PostMapping ("/insert")
    public AjaxResult insertUser( @RequestBody User user){
        return AjaxResult.success(userService.insertUser(user));
    }

    @ApiOperation(value = "更新一个用户(224 魏川子)",notes = "更新一个用户信息")
    @PutMapping("/update")
    public AjaxResult updateUser(@Validated @org.springframework.web.bind.annotation.RequestBody User user){
        return AjaxResult.success(userService.updateUser(user));
    }

    @ApiOperation(value = "删除一个用户(224 魏川子)",notes = "删除一个用户")
    @DeleteMapping("/{id}")
    public AjaxResult deleteUser(@PathVariable Long id ){
        return AjaxResult.success(userService.deleteUserById(id));
    }

}
